<template>
  <el-select v-model="currValue" :placeholder="placeholder" clearable class="!w-240px">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="Number(item.value)"
    />
  </el-select>
</template>
<script lang="ts" setup>
/** 通用选择框 **/
defineOptions({ name: 'CommonSelect' })

interface Options {
  value: string
  label: string
}

const props = defineProps({
  /** 下拉框选中值 **/
  modelValue: {
    type: null,
    default: undefined
  },
  options: {
    type: Array<Options>,
    default: () => [
      {
        value: '1',
        label: '是'
      },
      {
        value: '0',
        label: '否'
      }
    ]
  },
  placeholder: {
    type: String,
    default: () => {
      return `请选择内容`
    }
  }
})
const emit = defineEmits(['update:modelValue'])

const currValue = computed({
  get() {
    return props.modelValue
  },
  set(value: any) {
    emit('update:modelValue', value)
  }
})
</script>
